<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : shopmessage.class.php   FILE_PATH : \\classes\application\shopmessage.class.php
 * ....商铺留言类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri Sep 07 15:33:44 CST 2007
 */

class ShopMessageClass extends FrameWork {
	/**
	 * 商铺留言
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function addMessage($input_param){
		$valueArray = array();
		$valueArray['member_name'] = $input_param['MemberName'];
		$valueArray['message_content'] = $input_param['txtMessage'];
		$valueArray['shop_id'] = $input_param['hideShopID'];
		$valueArray['message_time'] = time();
		$insert_rs = $GLOBALS['db']->InsertRow($valueArray, 'shop_message', 'message_id');
		return $insert_rs;
	}
	
	/**
	 * 店主回复商铺留言
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function reMessage($input_param){
		$valueArray = array();
		$valueArray['shop_id'] = $input_param['hideShopID'];
		$valueArray['message_id'] = $input_param['hideMessageID'];
		$valueArray['message_recontent'] = $input_param['txtReMessage'];
		$valueArray['re_time'] = time();
		$update_rs = $GLOBALS['db']->UpdateRow($valueArray["message_id"],$valueArray, 'shop_message', 'message_id');
		return $update_rs;
	}
	
	/**
	 * 删除商铺留言
	 *
	 * @param var[] $input_id
	 * @param int $shop_id
	 * @return boolen
	 */
	function deleteOperateMessage($input_id,$shop_id){
		if (is_array($input_id)){
			foreach ($input_id as $value){
				$this->_deleteMessage($value,$shop_id);
			}
		}else{
			$this->_deleteMessage($input_id,$shop_id);
		}
		return true;
	}
	
	/**
	 * 删除某个商铺某个留言
	 *
	 * @param int $input_id 留言ID
	 * @param int $shop_id 商铺ID
	 * @return boolen
	 */
	function _deleteMessage($input_id,$shop_id){
		if (intval($input_id) > 0){
			$del_rs = $GLOBALS['db']->DeleOneRow('','shop_message',''," and message_id = " . intval($input_id) . " and shop_id='" . $shop_id . "'");
		}
		return $del_rs;
	}
	
	/**
	 * 通过 留言ID删除留言
	 * @author workflow Develop Team     
	 * @param  $msg_id 信息ID
	 * @return bool
	 */
	function delMessage($msg_id){
		if (intval($msg_id) > 0){
			$result = $GLOBALS['db']->DeleOneRow($msg_id,'shop_message','message_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 查看留言
	 *
	 * @param int $shop_id
	 */
	function getMessage(&$obj_page,$shop_id="",$isre=false,$condition=''){
		if ($shop_id != ""){
			 $substr .= "and shop_info.shop_id='" . $shop_id . "' ";
		}
		//检索条件
		if ($condition['shop_name'] != ''){
			$substr .= " and shop_info.shop_name like '%" . $condition['shop_name'] . "%'";
		}
		if ($condition['member_name'] != ''){
			$substr .= " and shop_message.member_name = '" . $condition['member_name'] . "'";
		}
		if ($condition['seller'] != ''){
			$substr .= " and member.login_name = '" . $condition['seller'] . "'";
		}
		
		$message_array = $GLOBALS['db']->GetJoinList($obj_page,array('shop_message','shop_info','member'),"inner join",array("shop_message.shop_id=shop_info.shop_id",'shop_info.member_id=member.member_id'),array('*','shop_name','login_name'),$substr,array(" message_time desc"));
		return $message_array;
	}
	
	/**
	 * 得到某条留言
	 *
	 * @param int $message_id  留言ID
	 * @param int $shop_id   商铺ID
	 * @return var[]
	 */
	function getOneMessage($message_id,$shop_id){
		if (intval($shop_id) > 0){
			$message_array = $GLOBALS['db']->GetJoinList($obj_page,array('shop_message','shop_info','member'),"left join",array("shop_message.shop_id=shop_info.shop_id",'shop_info.member_id=member.member_id'),array("*","shop_name",'login_name'),"where shop_message.shop_id='" . $shop_id . "' and shop_message.message_id='" . $message_id . "'",0,array(" message_time desc"));
			return $message_array;
		}else {
			return false;
		}
		
	}
	
	/**
	 * 查看留言
	 *
	 * @param int $shop_id   商铺ID
	 * @param int $limit   显示数量
	 * @return var[]
	 */
	function getLimitMessage($shop_id,$limit=3){
		$message_array = $GLOBALS['db']->GetList("and shop_id='" . $shop_id . "' and message_recontent<>'' order by message_time desc limit 0," . $limit,$page," shop_message");
		return $message_array;
	}
	
	/**
	 * 删除店主回复商铺留言
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function clearreMessage($input_param){
		$valueArray = array();
		$valueArray['shop_id'] = $input_param['shopid'];
		$valueArray['message_id'] = $input_param['messageid'];
		$valueArray['message_recontent'] = "";
		$valueArray['re_time'] = "";
		$update_rs = $GLOBALS['db']->UpdateRow($valueArray["message_id"],$valueArray, 'shop_message', 'message_id');
		return $update_rs;
	}
	
	/**
	 * 更新留言信息
	 * @author workflow Develop Team     
	 * @param  $param 更新参数
	 * @return bool
	 */
	function updateMessage($param){
		if (intval($param['message_id']) > 0){
			$valueArray = array();
			foreach ($param as $k => $v){
				$valueArray[$k] = $v;
			}
			$result = $GLOBALS['db']->UpdateRow(intval($valueArray['message_id']),$valueArray, 'shop_message', 'message_id');
			unset($value_array,$valueArray);
			return $result;
		}else {
			return false;
		}
	}
}
?>